package com.engine.kq.biz;

import com.engine.kq.wfset.util.KQAttFlowCheckUtil;
import weaver.cache.CacheBase;
import weaver.cache.CacheColumn;
import weaver.cache.CacheColumnType;
import weaver.cache.PKColumn;
import weaver.general.StaticObj;
import weaver.general.Util;
import weaver.systeminfo.SystemEnv;

/**
 * 假期规则缓存类
 */
public class KQLeaveRulesComInfo extends CacheBase {

    /**
     * 数据来源
     */
    protected static String TABLE_NAME = "kq_leaveRules";
    /**
     * sql中的where信息，不要以where开始
     */
    protected static String TABLE_WHERE = " (isDelete is null or isDelete !=1) ";
    /**
     * sql中的order by信息，不要以order by开始
     */
    protected static String TABLE_ORDER = " showOrder,id ";

    /**
     * 主键
     */
    @PKColumn(type = CacheColumnType.NUMBER)
    protected static String PK_NAME = "id";

    /**
     * 假期规则名称
     */
    @CacheColumn(name = "leaveName")
    protected static int leaveName;

    /**
     * 是否禁用：0-未禁用、1-已禁用
     */
    @CacheColumn(name = "isEnable")
    protected static int isEnable;

    /**
     * 应用范围：0-总部、1-分部
     */
    @CacheColumn(name = "scopeType")
    protected static int scopeType;

    /**
     * 分部ID(当应用范围为分部时选择的分部ID)
     */
    @CacheColumn(name = "scopeValue")
    protected static int scopeValue;

    /**
     * 最小请假单位
     * 1-按天请假
     * 2-按半天请假
     * 3-按小时请假
     * 4-按整天请假
     * 其他：无效数据
     */
    @CacheColumn(name = "minimumUnit")
    protected static int minimumUnit;

    /**
     * 余额单位变更时的换算比例
     * XX小时=1天
     */
    @CacheColumn(name = "proportion")
    protected static int proportion;

    /**
     * 日折算时长（1天=XX小时）
     */
    @CacheColumn(name = "hoursToDay")
    protected static int hoursToDay;

    /**
     *  按自然日计算请假时长，0-不排除，1-排除节假日，2-排除休息日，3-排除节假日和休息日
     */
    @CacheColumn(name = "filterHolidays")
    protected static int filterHolidays;

    /**
     * 计算请假时长方式：
     * 1-按工作日计算请假时长
     * 2-按自然日计算请假时长
     */
    @CacheColumn(name = "computingMode")
    protected static int computingMode;

    /**
     * 启用假期余额：
     * 0-不启用
     * 1-启用
     */
    @CacheColumn(name = "balanceEnable")
    protected static int balanceEnable;

    /**
     * 假期类型标识
     */
    @CacheColumn(name = "leaveCode")
    protected static int leaveCode;

    /**
     * 半天单位 时间选择方式：1-下拉框选择 、2-具体时间
     */
    @CacheColumn(name = "timeselection")
    protected static int timeselection;

    /**
     * 折算方式 1是四舍五入 2是向上取整 3是向下取整
     */
    @CacheColumn(name = "conversion")
    protected static int conversion;

    /**
     * 假期类型标识(新增-假期类型)
     */
    @CacheColumn(name = "leaveType")
    protected static int leaveType;

    public String getId(){
        return (String)getRowValue(PK_INDEX);
    }

    public String getLeaveName() {
        return (String)getRowValue(leaveName);
    }

    public String getLeaveName(String key){
        return (String) getValue(leaveName,key);
    }

    public String getIsEnable() {
        return (String)getRowValue(isEnable);
    }

    public String getIsEnable(String key){
        return (String) getValue(isEnable,key);
    }

    public String getScopeType() {
        return (String)getRowValue(scopeType);
    }

    public String getScopeType(String key){
        return (String) getValue(scopeType,key);
    }

    public String getScopeValue() {
        return (String)getRowValue(scopeValue);
    }

    public String getScopeValue(String key){
        return (String) getValue(scopeValue,key);
    }

    public String getMinimumUnit() {
        return (String)getRowValue(minimumUnit);
    }

    public String getMinimumUnit(String key){
        return (String)getValue(minimumUnit,key);
    }

    public String getProportion() {
        return (String)getRowValue(proportion);
    }

    public String getProportion(String key){
        return (String)getValue(proportion,key);
    }

    public String getHoursToDay() {
        return (String)getRowValue(hoursToDay);
    }

    public String getHoursToDay(String key){
        return (String)getValue(hoursToDay,key);
    }
    public String getFilterHolidays() {
        return (String)getRowValue(filterHolidays);
    }

    public String getFilterHolidays(String key){
        return (String)getValue(filterHolidays,key);
    }

    public String getComputingMode() {
        return (String)getRowValue(computingMode);
    }

    public String getComputingMode(String key){
        return (String)getValue(computingMode,key);
    }

    public String getBalanceEnable() {
        return (String)getRowValue(balanceEnable);
    }

    public String getBalanceEnable(String key){
        return (String)getValue(balanceEnable,key);
    }

    public String getLeaveCode() {
        return (String)getRowValue(leaveCode);
    }

    public String getLeaveCode(String key){
        return (String)getValue(leaveCode,key);
    }

    public String getLeaveType() {
        return (String)getRowValue(leaveType);
    }

    public String getLeaveType(String key) {
        return (String)getValue(leaveType,key);
    }

    public String getTimeSelection() {
        String value = (String) getRowValue(timeselection);
        if (value == null || value.equals("")) {
            value = "1";
        }
        return value;
    }

    public String getTimeSelection(String key) {
        String value = (String) getValue(timeselection, key);
        if (value == null || value.equals("")) {
            value = "1";
        }
        return value;
    }

  public String getConversion() {
    return (String)getRowValue(conversion);
  }

  public String getConversion(String key){
    return (String)getValue(conversion,key);
  }

    public String getUnitName(int language){
        String unitName = "";//单位名称，天/小时
        int minimumUnit = Util.getIntValue(getMinimumUnit(),1);
        if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) {
            unitName = SystemEnv.getHtmlLabelName(389325, language);//(天)
        } else {
            unitName = SystemEnv.getHtmlLabelName(389326, language);//(小时)
        }
        return unitName;
    }

    public String getUnitName(String key,int language){
        String unitName = "";//单位名称，天/小时
        int minimumUnit = Util.getIntValue(getMinimumUnit(key),1);
        if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) {
            unitName = SystemEnv.getHtmlLabelName(389325, language);//(天)
        } else {
            unitName = SystemEnv.getHtmlLabelName(389326, language);//(小时)
        }
        return unitName;
    }


    @Override
    public void removeCache() {
      super.removeCache();
      KQAttFlowCheckUtil kqAttFlowCheckUtil = new KQAttFlowCheckUtil();
      kqAttFlowCheckUtil.initLeaveUnit();
    }

}
